<template>
  <el-dialog title="新增拜访" :visible.sync="value" width="370px" :before-close="beforeClose">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="企业名称" prop="unitOrgCode">
        <el-select
          v-model="form.unitOrgCode"
          filterable
          remote
          placeholder="请输入关键词"
          :remote-method="remoteMethod"
        >
          <el-option
            v-for="item in unitNameList"
            :key="item.id"
            :label="item.unitName"
            :value="item.unitOrgCode"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="拜访时间" prop="visitTime">
        <el-date-picker
          v-model="form.visitTime"
          value-format="yyyy-MM-dd"
          type="date"
					placeholder="选择日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="拜访事由" prop="visitSubjectMatter">
        <el-input v-model="form.visitSubjectMatter" placeholder="请输入内容"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="visitRemark">
        <el-input v-model="form.visitRemark" placeholder="请输入内容"></el-input>
      </el-form-item>
    </el-form>
    <el-button class="submit-btn" @click="submit">
      提交
      <i class="el-icon-arrow-right"></i>
    </el-button>
  </el-dialog>
</template>
<script>
import { simpleQueryEnterprise, commitVisitRecord } from '@/api/visit';
export default {
  props: {
    value: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return {
			unitNameList: [],
      form: {
        unitOrgCode: "",
        visitTime: "",
        visitSubjectMatter: "",
        visitRemark: ""
      },
    };
  },
  methods: {
    remoteMethod(query) {
      if (query !== "") {
        simpleQueryEnterprise({
          unitName: query
        }).then(res => {
          this.unitNameList = res.data;
        })
      } else {
        this.unitNameList = [];
      }
    },
    submit() {
      commitVisitRecord(this.form).then(res => {
        this.$message.success("操作完成");
				this.$emit("refresh");
        this.beforeClose()
      });
    },
    beforeClose() {
      this.form = {
        taskIdList: [],
        recordId: "",
        enterpriseId: "",
        isPass: true
      };
      this.$emit("input", false);
    }
  }
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog .el-dialog__body {
  padding: 30px 0 0;
}

.el-form {
  padding: 0 10px;
}

.check-list {
  padding: 0 40px;
}

.submit-btn {
  width: 100%;
  height: 44px;
  background: #1c4088;
  box-shadow: 0px 4px 48px 32px rgba(6, 23, 80, 0.05);
  border-radius: 0;
  color: #ffffff;
  border: none;
}
</style>